﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ylh.BLL;
using System.Data;
using ExtAspNet;

public partial class _Default : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PreLoadTv();
        }
    }

    /// <summary>
    /// 
    /// </summary>
    private void PreLoadTv()
    {
        //if (StaffLoginName.ToLower() == "admin")
        //{
        //    //权限后续来做
        //}
        //else
        //{

        //}

        LoadTv();

    }

    private void LoadTv()
    {
        CompetenceBLL combll = new CompetenceBLL(DbConnectionStr);

        DataTable dt;

        if (StaffLoginName.ToLower() == "admin")
        {
            dt = combll.GetCompetenceByCode();
        }
        else
        {
            dt = combll.GetCompetenceByID(0, true);
        }
        ExtAspNet.TreeNode tn;

        foreach (DataRow dr in dt.Rows)
        {

            if (StaffLoginName.ToLower() != "admin")
            {
                if (!CheckCheckBox(dr["CompetenceID"].ToString()))
                {
                    continue;
                }
            }



            tn = new ExtAspNet.TreeNode();

            tn.EnableCheckBox = false;

            tn.Text = dr["CompetenceName"].ToString();

            tn.Expanded = true;
            tn.NodeID = dr["CompetenceID"].ToString();

            LoadChildNode(tn);
            treeMenu.Nodes.Add(tn);
        }
    }

    private bool CheckCheckBox(string ComID)
    {
        if (Competencelist.Contains(ComID)) return true;
        return false;
    }

    private void LoadChildNode(ExtAspNet.TreeNode tn)
    {
        CompetenceBLL combll = new CompetenceBLL(DbConnectionStr);
        DataTable dt = combll.GetCompetenceByID(Convert.ToDecimal(tn.NodeID), true);

        ExtAspNet.TreeNode tn1;

        foreach (DataRow dr in dt.Rows)
        {
            if (StaffLoginName.ToLower() != "admin")
            {
                if (!CheckCheckBox(dr["CompetenceID"].ToString()))
                {
                    continue;
                }
            }
            tn1 = new ExtAspNet.TreeNode();
            tn1.EnableCheckBox = false;
            tn1.Expanded = true;
            tn1.Text = dr["CompetenceName"].ToString();
            tn1.NodeID = dr["CompetenceID"].ToString();
            tn1.NavigateUrl = dr["Url"].ToString();
            LoadChildNode(tn1);
            tn.Nodes.Add(tn1);
        }

    }





}